// pages/detail/detail.js
var WxParse = require('../../wxParse/wxParse.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    imgDetialUrls:[
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    array: [],
    index:0,
    goods:'',
    shorttitle:'',
    subtitle:'',
    cardNum:'',
    passNum:'',
    optionid:'',
    goodsid:''
  },
  radioChange: function (e) {
    var aa = e.detail.value.split(',');
    this.setData({
      optionid: aa[1]
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      goods: options.goods,
      cardNum: options.cardNum,
      passNum: options.passNum
    })
  },
  gotoDui:function(){
    var that = this;
    wx.request({
      url: app.globalData.api + '&r=exchange.exchange_goods.success_dh',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      data: {
        goodsid: that.data.goodsid,
        key: that.data.passNum,
        serial: that.data.cardNum,
        optionid: that.data.optionid,
      },
      success: function (res) {
        console.log(res);
      },
      error:function(){
        console.log('请求错误');
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    wx.request({
      url: app.globalData.api + '&r=exchange.exchange_goods.getgoodsinfo',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      data: {
        goodsid:this.data.goods
      },
      success: function (res) {
        if (res.statusCode==200){
          that.setData({
            array:res.data.status.goods_option,
            shorttitle: res.data.status.goods_info.shorttitle,
            subtitle: res.data.status.goods_info.subtitle,
            imgUrls: res.data.status.goods_info.thumb_url,
            goodsid:res.data.status.goods_info.id
          })
          var t = res.data.status.goods_info.content;
          WxParse.wxParse('that.data.imgDetialUrls', 'html', t, that,"5");
          var newinglist=[];
          for (var link of app.globalData.imglist){
            var lis=app.globalData.imgapi + link;
            newinglist.push(lis)
          }
          that.setData({
            imgDetialUrls: newinglist
          })
        }else{
          wx.showModal({
            title: '提示',
            content: '网络错误',
            showCancel: false,
            success(res) {
              if (res.confirm) {
                wx.navigateBack({
                  delta: 1
                })
              }
            }
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})